from utils import create_chrome_driver,add_cookies,test
import json
import time
from selenium.webdriver.common.by import By

browser=create_chrome_driver()
time.sleep(1)
browser.get('https://taobao.com')


el=browser.find_element(by=By.XPATH,value='//*[@id="q"]')
el.send_keys('手机')
time.sleep(1)

el=browser.find_element(by=By.XPATH,value='//*[@id="J_TSearchForm"]/div[1]/button')
el.click()
time.sleep(1)
# #滚动到底部
# js="window.scrollTo(0,450);"
# driver.execute_script(js)
# sleep(3)
# 或者
js = "var q=document.documentElement.scrollTop=4514"
browser.execute_script(js)
time.sleep(1)
# 点击下一页
el=browser.find_element(by=By.XPATH,value='//*[@id="root"]/div/div[3]/div[1]/div[1]/div[2]/div[4]/div/div/button[2]')
el.click()
time.sleep(1)


#直接搜索页带参数会有反爬虫验证码
# browser.get('https://s.taobao.com/search?commend=all&ie=utf8&initiative_id=tbindexz_20170306&q=电脑&search_type=item&sourceId=tb.index&spm=a21bo.jianhua.201856-taobao-item.2&ssid=s5-e')
# browser.get('https://login.taobao.com/member/login.jhtml')
# time.sleep(1)

# el=browser.find_element(by=By.XPATH,value='//*[@id="fm-login-id"]')
# el.send_keys('15898987838')

# el=browser.find_element(by=By.XPATH,value='//*[@id="fm-login-password"]')
# el.send_keys('15898987838')

# el=browser.find_element(by=By.XPATH,value='//*[@id="login-form"]/div[4]/button')
# el.click()

# browser.get('https://s.taobao.com/search?q=手机')
# time.sleep(6)
# with open('taobao_cookie.json','w') as file:
#     json.dump(browser.get_cookies(), file)
# print(browser.page_source)
time.sleep(600)